<template><div><h2 id="帮助函数" tabindex="-1"><a class="header-anchor" href="#帮助函数"><span>帮助函数</span></a></h2>
<h3 id="admin-redirect" tabindex="-1"><a class="header-anchor" href="#admin-redirect"><span>admin_redirect</span></a></h3>
<blockquote>
<p>Since <code v-pre>v2.1.7-beta</code></p>
</blockquote>
<p>跳转到指定<code v-pre>url</code>，此函数可用于代替<code v-pre>redirect</code>函数，支持<code v-pre>pjax</code>以及<code v-pre>ajax</code>请求</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 不需要添加admin前缀</span></span>
<span class="line"><span class="token keyword">return</span> <span class="token function">admin_redirect</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'auth/users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 如果想要跳转到非admin前缀的链接，需要传递完整url链接</span></span>
<span class="line"><span class="token keyword">return</span> <span class="token function">admin_redirect</span><span class="token punctuation">(</span><span class="token function">url</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-exit" tabindex="-1"><a class="header-anchor" href="#admin-exit"><span>admin_exit</span></a></h3>
<p><code v-pre>admin_exit</code> 用于中断程序执行，并响应数据到浏览器进行显示，用于代替 <code v-pre>exit</code> 和 <code v-pre>die</code>，下面简单介绍下用法</p>
<p>用法1，返回 <code v-pre>Content</code> 布局对象，此用法可用于返回错误信息显示到前端</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Widgets<span class="token punctuation">\</span>Alert</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Layout<span class="token punctuation">\</span>Content</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 中断程序，并显示自定义页面到前端</span></span>
<span class="line"><span class="token function">admin_exit</span><span class="token punctuation">(</span></span>
<span class="line">    <span class="token class-name static-context">Content</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">title</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'标题'</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">description</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'描述'</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">body</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'页面内容1'</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">body</span><span class="token punctuation">(</span><span class="token class-name static-context">Alert</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'服务器出错了~'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'Error'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">danger</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>效果如下</p>
<p><img src="@source/dcat-admin-2x/assets/images/be70996f-d7de-421c-a57e-f610e94bb57f-FLg6C7kwRq.png" alt=""></p>
<p>用法2，返回 <code v-pre>json</code> 格式数据，此用法经常用于表单提交数据的<code v-pre>api</code>请求拦截，或<code v-pre>Action</code>的<code v-pre>api</code>请求拦截</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Admin</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token function">admin_exit</span><span class="token punctuation">(</span></span>
<span class="line">    <span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">success</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'成功了'</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">refresh</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">            <span class="token operator">...</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 当然也可以直接响应数组</span></span>
<span class="line"><span class="token function">admin_exit</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">   <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>用法3，直接响应<code v-pre>Response</code>对象或字符串</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_exit</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Hello world'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token function">admin_exit</span><span class="token punctuation">(</span><span class="token function">response</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Hello world'</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-color" tabindex="-1"><a class="header-anchor" href="#admin-color"><span>admin_color</span></a></h3>
<p>获取内置颜色，关于主题颜色更多用法请参考<a href="https://learnku.com/docs/dcat-admin/2.x/basic-use/theme.md#color" target="_blank" rel="noopener noreferrer">主题 - 颜色</a>章节</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 获取主题色的三种方式</span></span>
<span class="line"><span class="token variable">$primary</span> <span class="token operator">=</span> <span class="token function">admin_color</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'primary'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$primary</span> <span class="token operator">=</span> <span class="token function">admin_color</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'primary'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$primary</span> <span class="token operator">=</span> <span class="token function">admin_color</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">primary</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$color</span> <span class="token operator">=</span> <span class="token function">admin_color</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$color</span><span class="token operator">-></span><span class="token function">lighten</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'primary'</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-js" tabindex="-1"><a class="header-anchor" href="#admin-js"><span>admin_js</span></a></h3>
<p>可以在任意位置引入<code v-pre>js</code>文件，更多用法参考<a href="https://learnku.com/docs/dcat-admin/2.x/basic-use/assets.md" target="_blank" rel="noopener noreferrer">静态资源</a>章节</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_js</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'@admin/xxx.js'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-css" tabindex="-1"><a class="header-anchor" href="#admin-css"><span>admin_css</span></a></h3>
<p>可以在任意位置引入<code v-pre>css</code>文件，更多用法参考<a href="https://learnku.com/docs/dcat-admin/2.x/basic-use/assets.md" target="_blank" rel="noopener noreferrer">静态资源</a>章节</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_css</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'@admin/xxx.css'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-require-assets" tabindex="-1"><a class="header-anchor" href="#admin-require-assets"><span>admin_require_assets</span></a></h3>
<p>可以在任意位置引入静态资源组件，更多用法参考<a href="https://learnku.com/docs/dcat-admin/2.x/basic-use/assets.md" target="_blank" rel="noopener noreferrer">静态资源</a>章节</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_require_assets</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'@datime'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-path" tabindex="-1"><a class="header-anchor" href="#admin-path"><span>admin_path</span></a></h3>
<p>获取<code v-pre>Dcat Admin</code>安装的应用路径，默认目录是<code v-pre>app/Admin</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$bootstrap</span> <span class="token operator">=</span> <span class="token function">admin_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'bootstrap.php'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-url" tabindex="-1"><a class="header-anchor" href="#admin-url"><span>admin_url</span></a></h3>
<p>获取<code v-pre>Dcat Admin</code>应用的路由完整url：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 返回： http://localhost/admin/auth/users</span></span>
<span class="line"><span class="token variable">$url</span> <span class="token operator">=</span> <span class="token function">admin_url</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'auth/users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-route" tabindex="-1"><a class="header-anchor" href="#admin-route"><span>admin_route</span></a></h3>
<p>根据别名获取URL</p>
<p><code v-pre>app/Admin/routes.php</code>路由注册如下</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Route</span><span class="token operator">::</span><span class="token function">group</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'prefix'</span>        <span class="token operator">=></span> <span class="token function">config</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'admin.route.prefix'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'namespace'</span>     <span class="token operator">=></span> <span class="token function">config</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'admin.route.namespace'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'middleware'</span>    <span class="token operator">=></span> <span class="token function">config</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'admin.route.middleware'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Router</span> <span class="token variable">$router</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 设置别名</span></span>
<span class="line">    <span class="token variable">$router</span><span class="token operator">-></span><span class="token function">resource</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'UserController'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'names'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'index'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'my-users'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>根据别名获取URL</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 获取url</span></span>
<span class="line"><span class="token variable">$url</span> <span class="token operator">=</span> <span class="token function">admin_route</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 获取url并附带请求参数</span></span>
<span class="line"><span class="token variable">$url</span> <span class="token operator">=</span> <span class="token function">admin_route</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span><span class="token operator">=></span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 判断路由</span></span>
<span class="line"><span class="token variable">$isUsers</span> <span class="token operator">=</span> <span class="token function">request</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">routeIs</span><span class="token punctuation">(</span><span class="token function">admin_route_name</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-base-path" tabindex="-1"><a class="header-anchor" href="#admin-base-path"><span>admin_base_path</span></a></h3>
<p>获取<code v-pre>Dcat Admin</code>应用的路由路径：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 返回： /admin/auth/users</span></span>
<span class="line"><span class="token variable">$path</span> <span class="token operator">=</span> <span class="token function">admin_base_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'auth/users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-toastr" tabindex="-1"><a class="header-anchor" href="#admin-toastr"><span>admin_toastr</span></a></h3>
<p>在页面刷新后弹出一个<code v-pre>toastr</code>提示窗，参数：</p>
<ul>
<li><code v-pre>$message</code> 提示窗内容</li>
<li><code v-pre>$type</code> 提示窗类型，默认<code v-pre>success</code>，支持<code v-pre>success</code>、<code v-pre>info</code>、<code v-pre>warning</code>、<code v-pre>error</code></li>
<li><code v-pre>$options</code> toastr配置参数</li>
</ul>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_toastr</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'更新成功'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'success'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-success" tabindex="-1"><a class="header-anchor" href="#admin-success"><span>admin_success</span></a></h3>
<p>在页面刷新后在页面顶部显示一个成功消息：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_success</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'标题'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'成功了'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-error" tabindex="-1"><a class="header-anchor" href="#admin-error"><span>admin_error</span></a></h3>
<p>在页面刷新后在页面顶部显示一个错误消息：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_error</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'标题'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'失败了'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-warning" tabindex="-1"><a class="header-anchor" href="#admin-warning"><span>admin_warning</span></a></h3>
<p>在页面刷新后在页面顶部显示一个警告消息：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_warning</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'标题'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'警告'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-info" tabindex="-1"><a class="header-anchor" href="#admin-info"><span>admin_info</span></a></h3>
<p>在页面刷新后在页面顶部显示一个提示消息：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">admin_info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'标题'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'内容'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="admin-asset" tabindex="-1"><a class="header-anchor" href="#admin-asset"><span>admin_asset</span></a></h3>
<p>获取静态资源的完整链接：</p>
<blockquote>
<p>{tip} 此函数支持别名.</p>
</blockquote>
<div class="language-html line-numbers-mode" data-highlighter="prismjs" data-ext="html" data-title="html"><pre v-pre class="language-html"><code><span class="line">// 引入css</span>
<span class="line">&lt;link rel="stylesheet" href="{{ admin_asset("@admin/dcat-admin/main.min.css") }}"></span>
<span class="line"></span>
<span class="line">// 引入js</span>
<span class="line"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>{{ admin_asset('@admin/dcat-admin/main.min.js')}}<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-trans-field" tabindex="-1"><a class="header-anchor" href="#admin-trans-field"><span>admin_trans_field</span></a></h3>
<p>翻译当前控制器的字段，控制器名称去除<code v-pre>Controller</code>后缀之后再转化为小写中划线就是语言包的名称，如：控制器名称为<code v-pre>UserProfileController</code>，则对应的语言包名称为<code v-pre>user-profile.php</code>。</p>
<blockquote>
<p>{tip} 如果当前控制器对应的语言包中不存在该字段翻译，则会去公共翻译文件<code v-pre>global.php</code>中查找。</p>
</blockquote>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$name</span> <span class="token operator">=</span> <span class="token function">admin_trans_field</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$createdAt</span> <span class="token operator">=</span> <span class="token function">admin_trans_field</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'created_at'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><p>语言包内容如下：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'fields'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'name'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'名称'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'created_at'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'创建时间'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-trans-label" tabindex="-1"><a class="header-anchor" href="#admin-trans-label"><span>admin_trans_label</span></a></h3>
<p>翻译当前控制器的自定义内容，控制器名称去除<code v-pre>Controller</code>后缀之后再转化为小写中划线就是语言包的名称，如：控制器名称为<code v-pre>UserProfileController</code>，则对应的语言包名称为<code v-pre>user-profile.php</code>。</p>
<blockquote>
<p>{tip} 如果当前控制器对应的语言包中不存在该字段翻译，则会去公共翻译文件<code v-pre>global.php</code>中查找。</p>
</blockquote>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$user</span> <span class="token operator">=</span> <span class="token function">admin_trans_label</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'User'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>语言包内容如下：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'labels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'User'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'管理员'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="admin-trans-option" tabindex="-1"><a class="header-anchor" href="#admin-trans-option"><span>admin_trans_option</span></a></h3>
<p>翻译当前控制器的字段选项值，控制器名称去除<code v-pre>Controller</code>后缀之后再转化为小写中划线就是语言包的名称，如：控制器名称为<code v-pre>UserProfileController</code>，则对应的语言包名称为<code v-pre>user-profile.php</code>。</p>
<blockquote>
<p>如果当前控制器对应的语言包中不存在该字段翻译，则会去公共翻译文件<code v-pre>global.php</code>中查找。</p>
</blockquote>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$status</span> <span class="token operator">=</span> <span class="token function">admin_trans_option</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'status'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>语言包内容如下：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'options'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'status'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token number">1</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'启用'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token number">0</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'禁用'</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div></template>


